document.addEventListener("DOMContentLoaded", function() {
    // 获取所有的内容区域
    const contentSections = document.querySelectorAll('.content-section');
    contentSections.forEach(section => section.style.display = 'none'); // 默认隐藏所有内容区域

    // 获取导航栏中的元素
    const navElements = document.querySelectorAll('header span');
    const texts = {
        live: '暂未开放.........',
        scores: '这是比分的内容',
        teams: '这是球队信息的内容',
        players: '这是球员数据的内容',
        news: '这是新闻和文章的内容',
        comments: '这是用户评论的内容',
        rankings: '这是排行榜的内容'
    };
const spanElements=document.querySelectorAll('span');
spanElements.forEach(span=>{
    span.addEventListener('mouseover',function(){this.style.color='blue';})// 鼠标悬停时的颜色
    span.addEventListener('mouseout',function(){this.style.color='';}) // 恢复原始颜色
});

    navElements.forEach(navElement => {
        // 添加鼠标指针样式
        navElement.classList.add('cursor-pointer');
        navElement.addEventListener('click', function() {
            // 隐藏所有内容区域
            contentSections.forEach(section => section.style.display = 'none');
            
            // 显示当前点击的导航对应的内容区域
            const contentToShowId = `#${this.id.replace('nav-', 'content-')}`;
            const sectionToShow = document.querySelector(contentToShowId);
            if (sectionToShow) {
                sectionToShow.style.display = 'block';
                
                // 获取内容区域的文本元素
                const textElement = sectionToShow.querySelector('p');
                if (textElement) {
                    // 设置文本内容
                    textElement.textContent = tex[this.id];
                }
            }
        });
    });

    // 初始加载时显示第一个内容区域
    const firstContentSection = document.querySelector('#content-live');
    if (firstContentSection) {
        firstContentSection.style.display = 'block';
        
        // 设置初始文本
        const liveTextElement = firstContentSection.querySelector('#live-text');
        if (liveTextElement) {
            liveTextElement.textContent = texts.live;
        }
    }
let nan=['粟鑫鹏','真果粒'];
let pos=['前锋','中场','后卫',];
let gos=['1','2','3','4',];
let clu=['江源FC'];
  const playerRankings = [
    { rank: 7, playerName: nan[0], club: clu[0], age: 17, position: pos[0], goals: gos[3] },
    { rank: 6, playerName: nan[1], club: clu[0], age: 29, position: pos[2], goals: gos[3] },
    { rank: 5, playerName: 'sfd', club: clu[0] , age: 29, position: pos[1], goals: 3 }, // 注意：这里缺少了闭合引号，我假设这是一个错误并且已经修正
    { rank: 5, playerName: 'sfd', club: clu[0], age: 3, position: '', goals: 2 }, // 这里也缺少了闭合引号和位置信息，同样进行了假设性修正
   { rank: 5, playerName: 'sfd', club:  clu[0], age: 3, position: '', goals: 2 } ,
   { rank: 5, playerName: 'sfd', club: clu[0], age: 3, position: '', goals: 2 } ,
 
    // 更多球员...
];

// 对球员数据按进球数降序排序，但保留排名不变
playerRankings.sort((a, b) => b.goals - a.goals);

// 获取球员排行榜的tbody元素
const playerTableBody = document.querySelector('#player-ranking-table tbody');

// 清空之前的表格内容（如果有）
playerTableBody.innerHTML = '';

// 创建新的行并插入数据
playerRankings.forEach(player => {
    const row = `<tr>
        <td>${player.rank}</td>
        <td>${player.playerName}</td>
        <td>${player.club}</td>
        <td>${player.age}</td>
        <td>${player.position}</td>
        <td>${player.goals}</td>
    </tr>`;
     // 显示进球数而不是评分
    playerTableBody.innerHTML += row;
});
let jiuqiu=['1'];
let chachengjun=['1'];
let jieguo=["1 -3"];
let mingzi=['三中','怀中'];
    const teamData = {
    name: "江源FC",
    players: ['粟鑫鹏:进球'+jiuqiu[1]+'个', '查诚俊:进球'+chachengjun[0]+'个'],
    matches: [
      { opponent:mingzi[1], result: jieguo[0] },
    //   { opponent: "马德里竞技", result: "2 - 0" },
    //   { opponent: "瓦伦西亚", result: "1 - 1" }
    ]
  };
  document.getElementById("teamName").textContent = teamData.name;

    // 显示球员名单
    const playersListElement = document.getElementById("playersList");
    teamData.players.forEach(function(player) {
      const li = document.createElement("li");
      li.textContent = player;
      playersListElement.appendChild(li);
    });

    // 显示最近的比赛结果
    const matchesListElement = document.getElementById("matchesList");
    teamData.matches.forEach(function(match) {
      const li = document.createElement("li");
      li.textContent = `对阵 ${match.opponent}:${match.result}`;
      matchesListElement.appendChild(li);
    });
});
